home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Cream of the Crop 1
/
Cream of the Crop 1.iso
/
PRINTER
/
PROHP.ARJ
/
DPRINV.PRG
< prev
next >
Wrap
Text File
|
1992-06-23
|
9KB
|
243 lines
/*
┌─────────────────────────────────────────────────────────────────────────┐
│ │
│ Program : Prinv.prg │
│ Usage : │
│ Purpose : Demonstrate creating an invoices form with shadow boxes │
│ store it to a string type var make it as a macro and │
│ call it each time we need the form. │
│ also the option of saving the invoice to a file │
│ and download it later. │
│ │
│ Author : Copyright (C) 1992, I.L.A.,Inc. All Rights reserved. │
│ │
│ Comments: This source code may be distributed and used freely │
│ provided that the copyright notice is not removed. │
│ │
└─────────────────────────────────────────────────────────────────────────┘
*/
#include "prohp.ch"
proc main()
Local HPCinv:=""
set2print("dprinv.hpc")
HP_init()
HP_send(.T.)
// process the invoice internaly
HPscale(50)
PrInvoice(1,1,10,5)
HP_reset()
HP_orient(LANDSCAPE)
HPscale(100)
PrInvoice(0.3,0.3,9.5,3.5)
HP_reset()
HP_orient(PORTRAIT)
HPscale(100)
PrInvoice(1,1,6,5)
HP_reset()
// now we will test downloading this invoice
// DLinvoice()
// HP_reset()
set2screen()
return
Function PrInvoice(nTop,nLeft,nWidth,nInvH)
Local nInvoice:= 18000, nTotInv := 0
Local nRscale:=HPscale()/100 // used to adjust scale where
// HPscale() has no efect
Local aCompany:={"I.L.A., Inc. ","520 W. Hwy 436 #1180",;
"Altamonte Springs, FL 32714","Fax. (407) 774-6750"}
// Local nTop:=0.3,nLeft:=0.3
Local nLogoH:=2.2*nRscale
//Local nWidth:=7 // try changing the width and all the rest
// will be adjusted try it !
// Local nInvH:=5.5
Local nInvW:=nWidth
Local o:='',nBoxSpace:=0.2
Local nS2H:=1 // height of Sold to / ship to box
Local nS2W:=(nWidth-nBoxSpace)/2 // width of S2/S2 box
Local aSold2Box:={nTop+nLogoH,nLeft,nS2H,nS2W} //
Local aShip2Box:={nTop+nLogoH,nLeft+(nS2W*nRscale)+(nBoxSpace*nRscale),nS2H,nS2W}
Local aInvBox:={nTop+nLogoH+(aSold2Box[3]*nRscale)+(nBoxSpace*nRscale),nLeft,nInvH,nInvW}
local nWUnit:=nWidth/10*nRscale
// set array of Invoice column width
Local aColW:={nWUnit*1,nWUnit*6,nWUnit*1.2,nWUnit*1.8}
Local aInvTab:={nLeft,nLeft+nWUnit,nLeft+nWUnit*7,nLeft+nWUnit*8.2}
//Local aInvTab:={nLeft,aColW[1],aColW[1]+aColW[2],aColW[1]+aColW[2]+aColW[3]}
Local line:=0,nttop:=0,cInvoice:="",os,HPCinv:=''
Local ntdate,nQty,nUnitp,cDescr,aaddress,nLM
os:=HP_send(.f.)
HPshadow(.t.) // make shadow boxes
HPsetshadow(HPsetshadow()[1]*nRscale) // set shadow width
if HPscale() < 80
HPCinv+=HP_pitch(16,ITALIC)
HPCinv+=HP_lpi(8)
else
HPCinv+=HP_pitch(10,ITALIC)
HPCinv+=HP_lpi(5)
endif
ntTop:=nTop
// print company header
HPCinv+=HP_hline(ntTop,nLeft,nWidth,0.08,GFILLGRAY,40)
ntTop+=1.5/HP_data(D_LPI)
for line:=1 to len(aCompany)
HPCinv+=HP_atsay(ntTop,nLeft,aCompany[line])
ntTop+=1/HP_data(D_LPI)
next
HPCinv+=HP_hline(ntTop,nLeft,nWidth,0.08,GFILLGRAY,40)
ntTop+=1/HP_data(D_LPI)+0.08
nTdate:=ntTop // mark date line for later
// HPCinv+=HP_lpi(7)
// make "sold to" box
HPCinv+=HP_box(aSold2Box[1],aSold2Box[2],aSold2Box[3],aSold2Box[4])
HPCinv+=HP_atsay(aSold2Box[1]-0.5/HP_data(D_LPI),aSold2Box[2],"Sold To:")
// make "ship to" box
HPCinv+=HP_box(aShip2Box[1],aShip2Box[2],aShip2Box[3],aShip2Box[4])
HPCinv+=HP_atsay(aShip2Box[1]-0.5/HP_data(D_LPI),aShip2Box[2],"Ship To:")
// make invoice detail box
HPCinv+=HP_box(aInvBox[1],aInvBox[2],aInvBox[3],aInvBox[4])
HPCinv+=HP_hline(aInvBox[1]+1.5/HP_data(D_LPI),aInvBox[2],aInvBox[4])
HPCinv+=HP_hline(aInvBox[1],aInvBox[2],aInvBox[4],1.5/HP_data(D_LPI),GFILLGRAY,10)
HPCinv+=HP_pitch(16) // use small font for column header
// print column header at center of each col.
HPCinv+=HP_atsay(aInvBox[1]+1/HP_data(D_LPI),aInvBox[2]+;
(aColW[1]-HPstsize("QTY."))/2,"QTY.")
HPCinv+=HP_vline(aInvBox[1],aInvBox[2]+aColW[1],aInvBox[3])
HPCinv+=HP_atsay(aInvBox[1]+1/HP_data(D_LPI),aInvBox[2]+aColW[1]+;
(aColW[2]-HPstsize("Description"))/2,"Description")
HPCinv+=HP_vline(aInvBox[1],aInvBox[2]+aColW[1]+aColW[2],aInvBox[3])
HPCinv+=HP_atsay(aInvBox[1]+1/HP_data(D_LPI),aInvBox[2]+aColW[1]+aColw[2]+;
(aColW[3]-HPstsize("Unit"))/2,"Unit")
HPCinv+=HP_vline(aInvBox[1],aInvBox[2]+aColW[1]+aColW[2]+aColW[3],aInvBox[3])
HPCinv+=HP_atsay(aInvBox[1]+1/HP_data(D_LPI),aInvBox[2]+aColW[1]+aColw[2]+aColW[3]+;
(aColW[4]-HPstsize("Amount"))/2,"Amount")
// Invocie format is done and we have all it in HPCinv
HP_send(os) // restore output flag
if HPscale() < 80
HP_pitch(16)
else
HP_pitch(10,ITALIC)
endif
nInvoice:=18000 // invoice # to start
nQty:=1 // quantity
cDescr:="ProHP - Library for Laser Printer" // description
nUnitp:=99.00 // unit price
nLM:=1/HP_data(D_CPI) // Relative Left margin for column
/*
one option is to save this invoice format to a disk file for later use
one easy way is to save it using memowrit() and later download the
invoice using memoread(). do not forget to save the invoice coordinates
to print the invoice details after downloading.
*/
memowrit("invoice.mac",HPCinv) // save Invoice format to a file
// Open DBF file
select 1
use prohp alias pro
go top
/*
Let's store the invoice format into Macro so we do not need to send it
to the printer each time we print an invoice. it is faster because the
macro is stored in the printer memory and to activate it you send only
a call macro command.
*/
HP_stmacro(1) // open macro id # 1
qqout(HPCinv) // send to printer
HP_endmacro(1,PERMMACRO) // close macro 1 and save it from reset
if HPscale() < 80
HP_pitch(16)
HP_lpi(8)
else
HP_pitch(10,ITALIC) // set font to Courier 10 cpi Italic
HP_lpi(5) // 5 lines per inch
endif
while !eof()
HP_callmacro(1) // call macro # 1 (our invoice format)
// print date and invoice #
HP_atsay(nTdate,nLeft,"Date :"+dtoc(date()))
cInvoice:="Invoice # "+str(nInvoice,6)
// Right justify Invoice #
HP_atsay(nTdate,nLeft+(nWidth*nRscale)-HPstsize(cInvoice),cInvoice)
// read address into array
aAddress:={pro->name,pro->address,trim(pro->city)+', '+pro->state+' '+;
pro->zip}
// print Sold to and ship to address location using HP_aatsay()
HP_aatsay(aSold2Box[1]+1/HP_data(D_LPI),aSold2Box[2]+nLM,aAddress)
HP_aatsay(aShip2Box[1]+1/HP_data(D_LPI),aShip2Box[2]+nLM,aAddress)
// detail of invoice
HP_setpos(aInvBox[1]+2/HP_data(D_LPI),nLeft+nLM)
// while invoice here
HP_rcpos(1,,.t.) // down one line
// print quantity
HP_atsay(,aInvTab[1]+nLm,padl(str(nQty,4),HPi2col(aColW[1])-1))
// print description
HP_atsay(,aInvTab[2]+nLm,cDescr)
// print unit price
HP_atsay(,aInvTab[3]+nLm,padl(str(nUnitp,6,2),HPi2col(aColW[3])-1))
// print amount
HP_atsay(,aInvTab[4]+nLm,padl(str(nQty*nUnitp,9,2),HPi2col(aColW[4])-1))
nTotInv+=nQty*nUnitp
// enddo here
// print totals
HP_rcpos(2,,.t.) // 2 lines down
// print Total Amount
// first draw gray bar over the current line
HP_atsay(,aInvTab[2],HPgraytext(padl("",;
HPi2col(aColW[2]+aColW[3]+aColW[4]))))
// print 'Total '
HP_atsay(,aInvTab[3]-HPstsize("Total "),"Total ")
// Print the total amount
HP_atsay(,aInvTab[4]+nLm,padl(str(nTotInv,9,2),;
HPi2col(aColW[4])-1))
// print message at the bottom of the invoice
HP_atsay(aInvBox[1]+(aInvBox[3]*nRscale)-1/HP_data(D_LPI),aInvTab[2]+nLm,;
HPbold("DO NOT FORGET TO SEND REGISTRATION CARD."))
nInvoice++ // increment invoice number
HP_feed(FEEDOUT) // feed the page out. (no change to the printer environment)
if nInvoice=18001
exit
endif
skip // next record
enddo
return NIL
proc DLinvoice()
/*
This procedure demonstrate how it is simple and fast to
download previuosly built forms of any kind.
the two methods will work fine with most cases but we recomend
the use of HPdownload() which send the file in binary mode to
the printer and return .F. if error occur during downloading.
*/
Local HPCinv:=[], cfName:="invoice.mac"
if file(cfName) // make sure we have the file
HP_pitch(10)
HP_atsay(5,2,"Using MEMOREAD()")
HPCinv := memoread(cfName)
qqout(HPCinv) // or just qqout(memoread(cfName))
HP_feed(FEEDOUT)
HPdownload(cfName,"LPT1") // download invoice format
HP_atsay(5,2,"USING HPdownload()")
endif
return